package com.org.buildcycle2;

import org.anddev.andengine.entity.sprite.AnimatedSprite;
import com.org.buildcycle2.CharJumpActivity;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.Contact;
import com.badlogic.gdx.physics.box2d.ContactImpulse;
import com.badlogic.gdx.physics.box2d.ContactListener;
import com.badlogic.gdx.physics.box2d.Manifold;

public class MyContactListener implements ContactListener {

	//Sets up the variables/objects
	private AnimatedSprite dude;
	private Body body;

	public MyContactListener(AnimatedSprite dude, Body body) {
		super();
		this.dude = dude;
		this.body = body;
		
	}

	@Override
	//This function gets the actual figure of the sprite when the contact is made.
	public void beginContact(Contact contact) {
        final Body bodyA, bodyB;
        bodyA = contact.getFixtureA().getBody();
        bodyB = contact.getFixtureB().getBody();
        if((bodyA == CharJumpActivity.doubleJumpItem && bodyB == body) || (bodyA == body && bodyB == CharJumpActivity.doubleJumpItem)){
            CharJumpActivity.mScene.detachChild(CharJumpActivity.doubleJumpSprite);
            //CharJumpActivity.doubleJumpItem.setActive(false);
        	CharJumpActivity.setCurrentItem(0);
        }
        else{
        	CharJumpActivity.count = 0;
        	CharJumpActivity.inAir = false;
        	CharJumpActivity.setIsJumping(false);
        	CharJumpActivity.animateDude(dude,CharJumpActivity.getUpsideDown(), CharJumpActivity.STAND);
        	body.setLinearVelocity(new Vector2(0,0));
        }
	}
	

	@Override
	public void endContact(Contact contact) {

	}

	@Override
	public void preSolve(Contact contact, Manifold oldManifold) {

		//setIsJumping(false);
	}

	@Override
	public void postSolve(Contact contact, ContactImpulse impulse) {
		
	}

}
